package com.xm.xmapp.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.xm.xmapp.R;
import com.xm.xmapp.base.MyBaseAdapter;
import com.xm.xmapp.base.ViewHolder;
import com.xm.xmapp.response.bean.OrderBeanResponse;
import com.xm.xmapp.tools.StringTools;

public class TimeOrderListAdapter extends MyBaseAdapter<OrderBeanResponse> {
	private OnClickAble interFace;

	public TimeOrderListAdapter(ArrayList<OrderBeanResponse> list, Activity context, int layoutId) {
		super(list, context, layoutId);

	}

	public interface OnClickAble {
		void setTextView(View v, int position);// 点击评价

		Object DoSomeThing(Object data);// 查看详情
	}

	public OnClickAble getInterFace() {
		return interFace;
	}

	public void setInterFace(OnClickAble interFace) {
		this.interFace = interFace;
	}

	@SuppressWarnings("deprecation")
	@Override
	public void setValues(ViewHolder holder, final OrderBeanResponse t, final int position) {

		holder.setText(R.id.name, t.car_number)
				.setText(R.id.address, StringTools.getTime(t.add_time * 1000, "yyyy-MM-dd HH:mm:ss"))
				.setText(R.id.qidian, t.add_network_name).setText(R.id.zhongdian, t.return_network_name);

		int time = Integer.parseInt(t.car_off_minute_today_total) + Integer.parseInt(t.car_on_minute_today_total);

		holder.setText(R.id.pay, (time / 24 / 60 == 0 ? "" : time / 24 / 60 + "天")
				+ (time / 60 % 24 == 0 ? "" : time / 60 % 24 + "小时") + time % 60 + "分钟     " + t.pay_money + "元");

		// status--
		// `order_status` tinyint(1) DEFAULT '1' COMMENT
		// '订单状态：1=已下单，2=租赁中，3=已还车,4=已取消，5=锁定（不支持操作）',
		TextView status = (TextView) holder.getView(R.id.status);
		status.setOnClickListener(null);
		holder.getView(R.id.pay).setVisibility(View.VISIBLE);
		switch (t.order_status) {
		case "1":
			status.setText("已下单");

			status.setTextColor(activity.getResources().getColor(R.color.color6));
			status.setBackgroundDrawable(null);
			break;
		case "2":
			status.setText("用车中");
			holder.setText(R.id.pay, "");
			status.setTextColor(activity.getResources().getColor(R.color.color6));
			holder.getView(R.id.pay).setVisibility(View.INVISIBLE);
			status.setBackgroundDrawable(null);
			break;

		case "3":
			status.setText("已还车");
			if (!t.is_comment.equals("1")) {
				status.setText("去评价");
				status.setTextColor(activity.getResources().getColor(R.color.red_text_color));
				status.setBackgroundResource(R.drawable.line_red_bg_while);
				status.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						if (interFace != null) {
							interFace.setTextView(v, position);
						}
					}
				});

			} else {
				status.setTextColor(activity.getResources().getColor(R.color.color6));
				status.setBackgroundDrawable(null);
			}
			break;
		case "4":
			status.setText("已取消");

			status.setTextColor(activity.getResources().getColor(R.color.color6));
			status.setBackgroundDrawable(null);
			break;

		case "5":
			status.setText("锁单");
			holder.setText(R.id.pay, "");
			status.setTextColor(activity.getResources().getColor(R.color.color6));
			holder.getView(R.id.pay).setVisibility(View.INVISIBLE);
			status.setBackgroundDrawable(null);
			break;
		default:
			status.setText("锁单");

			status.setTextColor(activity.getResources().getColor(R.color.color6));
			status.setBackgroundDrawable(null);
			break;
		}

		holder.getConvertView().setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				if (interFace != null) {
					interFace.DoSomeThing(t);
				}
			}
		});

	}

}
